package com.huaqin.punan.sliding;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * Copyright (c) 2012
 * All rights reserved.
 * @Description BaseView
 * @author punan
 */
public class BaseView {

	public boolean isScroll=true;//是否可以滚动
	public View view;//主界面视图
	public MyMoveView myMoveView;//移动视图
	
	private Context context;
	private TextView textview;
	private Button leftButton;
	
	public BaseView(Context context){
		this.context = context;
	}
	
	/**
	 * 赋值移动视图
	 * @param myMoveView
	 */
	public void setMyMoveView(MyMoveView myMoveView) {
		this.myMoveView = myMoveView;
	}

	public boolean isScroll() {
		return isScroll;
	}

	public void setScroll(boolean isScroll) {
		this.isScroll = isScroll;
	}

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}
	
	public void init(){
		view = LayoutInflater.from(context).inflate(R.layout.main_view, null);
		textview = (TextView)view.findViewById(R.id.main_textview);
		leftButton = (Button)view.findViewById(R.id.settingsButton);
		
		leftButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				myMoveView.showHideLeftMenu();
			}
		});
		
		this.textview.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if(!isScroll() || myMoveView.getNowState() == MyMoveView.LEFT){
					return true;
				}
				return false;
			}
		});
		
	}
}
